{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_visualization:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Visualization"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. toctree::\n",
    "   :maxdepth: 1\n",
    "   :hidden:\n",
    "\n",
    "   scatter.ipynb\n",
    "   pcp.ipynb\n",
    "   heatmap.ipynb\n",
    "   petal.ipynb\n",
    "   radar.ipynb\n",
    "   radviz.ipynb\n",
    "   star.ipynb\n",
    "   video.ipynb\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Different visualization techniques are available. Each of them has different purposes and is suitable for less or higher dimensional objective spaces. \n",
    "\n",
    "The following visualizations can be used:\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "|Name|Class|\n",
    "|---|---|\n",
    "|[Scatter Plots (2D/3D/ND)](scatter.ipynb)|Scatter|\n",
    "|[Parallel Coordinate Plots (PCP)](pcp.ipynb)|ParallelCoordinatePlot|\n",
    "|[Heatmap](heatmap.ipynb)|Heatmap|\n",
    "|[Petal Diagram](petal.ipynb)|Petal|\n",
    "|[Radar](radar.ipynb)|Radar|\n",
    "|[Radviz](radviz.ipynb)|Radviz|\n",
    "|[Star Coordinates](star.ipynb)|StarCoordinate|\n",
    "|[Video](star.ipynb)|Video|\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Each of them is implemented in a class which can be used directly. However, it might\n",
    "be more comfortable to either use the factory function in some cases.\n",
    "For example for scatter plots the following initiates the same object:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# directly using the class\n",
    "from pymoo.visualization.scatter import Scatter\n",
    "plot = Scatter()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The advantages of the convenience function is that just by changing the string a different visualization \n",
    "can be chosen (without changing any other import). Moreover, we desire to keep the global interface in the factory the same, whereas the implementation details, such as class names might change. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Please note, that the visualization implementations are just a wrapper around [matplotlib](https://matplotlib.org) and all keyword arguments are still useable.\n",
    "For instance, if two different set of points should be plotted in different colors with different markers in a scatter plot:\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "A = np.random.random((20,2))\n",
    "B = np.random.random((20,2))\n",
    "\n",
    "plot = Scatter()\n",
    "plot.add(A, color=\"green\", marker=\"x\")\n",
    "plot.add(B, color=\"red\", marker=\"*\")\n",
    "plot.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This holds for all our visualizations. However, depending on the visualization the matplotlib function that is used and the corresponding keyword arguments might change. For example, in for the PetalWidth Plot polygons are drawn which has different keywords than the plot of matplotlib. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Furthermore, the plots have some default arguments to be used to set them during initialization:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymoo.visualization.petal import Petal\n",
    "from pymoo.visualization.util import default_number_to_text\n",
    "\n",
    "np.random.seed(5)\n",
    "A = np.random.random((1,6))\n",
    "\n",
    "plot = Petal(\n",
    "    \n",
    "    # change the overall figure size (does not work for all plots)\n",
    "    figsize=(8, 6),\n",
    "    \n",
    "    # directly provide the title (str or tuple for options)\n",
    "    title=(\"My Plot\", {\"pad\" : 30}),\n",
    "    \n",
    "    # plot a legend (tuple for options)\n",
    "    legend=False,\n",
    "    \n",
    "    # make the layout tight before returning\n",
    "    tight_layout=True,\n",
    "    \n",
    "    # the boundaries for normalization purposes (does not apply for every plot\n",
    "    # either 2d array [[min1,..minN],[max1,...,maxN]] or just two numbers [min,max]\n",
    "    bounds=[0,1],\n",
    "    \n",
    "    # if normalized, the reverse can be potted (1-values)\n",
    "    reverse=False,\n",
    "    \n",
    "    # the color map to be used\n",
    "    cmap=\"tab10\",\n",
    "    \n",
    "    # modification of the axis style\n",
    "    axis_style=None,\n",
    "    \n",
    "    # function to be used to plot numbers\n",
    "    func_number_to_text=default_number_to_text,\n",
    "    \n",
    "    # change the axis labels - could be a list just the prefix\n",
    "    axis_labels=[\"Objective %s\" % i for i in range(1,7)],\n",
    ")\n",
    "\n",
    "plot.add(A, label=\"A\")\n",
    "plot.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For each visualization a documentation is provided."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
